package com.bilibili.juc.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @author zuife
 * @description
 * @since 2024-04-28 21:08:42
 */
public class InterruptDemo {
    static volatile boolean isStop = false;

    public static void main(String[] args) {
        new Thread(() -> {
            while (true) {
                if(isStop){
                    System.out.println(Thread.currentThread().getName()+"\t isStop 被修改为true,程序停止");
                    break;
                }
                System.out.println("hello volatile");
            }
        }, "t1").start();
        try {
            TimeUnit.MILLISECONDS.sleep(20);
        } catch (InterruptedException e) {
           e.printStackTrace();
        }
        new Thread(() -> {
            isStop = true;
        }, "t2").start();
    }
}
